package com.zhanghp.class05;

import com.zhanghp.refer.TreeNode;

/**
 * <h1>判断一颗树是否为镜像树</h1>
 * <a href = "https://leetcode.cn/problems/symmetric-tree">leetcode</a>
 *
 * @author zhanghp
 * @since 2024/1/9 14:01
 */
public class Code03_SymmetricTree {

    public boolean isSymmetric(TreeNode root) {
        return symmeticTree(root, root);
    }

    public static boolean symmeticTree(TreeNode p, TreeNode q){
        if (p == null ^ q == null) {
            return false;
        }
        if (p == null) {
            return true;
        }
        return p.val == q.val && symmeticTree(p.left, q.right) && symmeticTree(p.right, q.left);
    }
}
